﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using System.Data.SqlClient;
using ECONTACT.Controller;

namespace ECONTACT
{
    public partial class frmGiaoVien : Form
    {
        GiaoVienCtrl m_GiaoVienCtrl = new GiaoVienCtrl();

        public frmGiaoVien()
        {
            InitializeComponent();
        }

        private void frmGiaoVien_Load(object sender, EventArgs e)
        {
            m_GiaoVienCtrl.HienThi(dGVGiaoVien, txtMaGiaoVien, txtTenGiaoVien, dtpNgaySinh, txtGioiTinh, ckbGTinhNam, ckbGTinhNu, txtSoDienThoai, txtEmail, txtDiaChi);
            DataService.OpenConnection();
        }

        private void dGVGiaoVien_CellClick(object sender, System.Windows.Forms.DataGridViewCellEventArgs e)
        {
            if (txtGioiTinh.Text == "True")
                ckbGTinhNu.Checked = true;
            else
                ckbGTinhNam.Checked = true;
        }

        private void btnThem_Click(object sender, EventArgs e)
        {
            bool gioiTinh = false;
            if (ckbGTinhNu.Checked == true)
                gioiTinh = true;

            String rs = m_GiaoVienCtrl.LuuGiaoVien(txtTenGiaoVien.Text, dtpNgaySinh.Value, gioiTinh, txtSoDienThoai.Text, txtEmail.Text, txtDiaChi.Text);
            if (!rs.Equals("Success"))
            {
                MessageBox.Show(rs);
            }
            m_GiaoVienCtrl.HienThi(dGVGiaoVien, txtMaGiaoVien, txtTenGiaoVien, dtpNgaySinh, txtGioiTinh, ckbGTinhNam, ckbGTinhNu, txtSoDienThoai, txtEmail, txtDiaChi);
        }

        private void btnCapNhat_Click(object sender, EventArgs e)
        {
            bool gioiTinh = false;
            if (ckbGTinhNu.Checked == true)
                gioiTinh = true;

            String rs = m_GiaoVienCtrl.UpdateGiaoVien(txtMaGiaoVien.Text, txtTenGiaoVien.Text, dtpNgaySinh.Value, gioiTinh, txtSoDienThoai.Text, txtEmail.Text, txtDiaChi.Text);
            if (!rs.Equals("Success"))
            {
                MessageBox.Show(rs);
            }
            m_GiaoVienCtrl.HienThi(dGVGiaoVien, txtMaGiaoVien, txtTenGiaoVien, dtpNgaySinh, txtGioiTinh, ckbGTinhNam, ckbGTinhNu, txtSoDienThoai, txtEmail, txtDiaChi);
        }

        private void btnXoa_Click(object sender, EventArgs e)
        {
            if (dGVGiaoVien.RowCount == 0)
            {
                MessageBox.Show("Bạn chưa chọn dòng nào làm sao xóa!", "Thông báo");
            }
            else if (MessageBoxEx.Show("Bạn có chắc là xóa thiệt hok ?", "DELETE", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                m_GiaoVienCtrl.DeleteGiaoVien(txtMaGiaoVien.Text);
                m_GiaoVienCtrl.HienThi(dGVGiaoVien, txtMaGiaoVien, txtTenGiaoVien, dtpNgaySinh, txtGioiTinh, ckbGTinhNam, ckbGTinhNu, txtSoDienThoai, txtEmail, txtDiaChi);
            }
        }
    }
}
